﻿using BCCommon;
using BCCommon.TMS.Driver;
using BCDto.TMS.WorkingReport;
using BCService.TMS.WorkingReport;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Net;

namespace BCTMSRESTful.Controllers.Management.TMS.WorkingReport
{
    /// <summary>
    /// 车辆运输问题分类接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class WorkingReportsController : ManagementBaseController
    {

        private readonly IWorkingReportService workingReportService;

        public WorkingReportsController(IWorkingReportService workingReportService)
        {
            this.workingReportService = workingReportService;
        }

        #region 获取工作上报信息列表（分页）
        /// <summary>
        ///  获取工作上报信息列表（分页）
        /// </summary>
        /// <param name="phone">手机号</param> 
        /// <param name="role">角色</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取工作上报信息列表（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<WorkingReportDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "phone")] string phone,
            [FromQuery(Name = "role")] DriverRoleType? role,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {

            if (this.Admin.IsSystemAccount)
            {
                return StatusCode((int)HttpStatusCode.OK, this.workingReportService.GetList((long?)null, phone, start, end, role, ascending, sortName, index, size));
            }
            return StatusCode((int)HttpStatusCode.OK, this.workingReportService.GetList(this.Admin.AgentRecord == null ? this.Admin.CompanyId : this.Admin.AgentRecord.CompanyId, phone, start, end, role, ascending, sortName, index, size));
        }
        #endregion

        #region 获取一条工作上报信息

        /// <summary>
        /// 获取工作上报信息
        /// </summary>
        /// <param name="workingReportId">工作上报信息Id</param>
        /// <returns></returns>
        /// <response code="200">查询工作上报信息成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpGet("{working_report_id}")]
        [ProducesResponseType(typeof(WorkingReportDto), 200)]
        public IActionResult Get([FromRoute(Name = "working_report_id")] long workingReportId)
        {
            return StatusCode((int)HttpStatusCode.OK, workingReportService.GetByWorkingReportId(workingReportId));
        }
        #endregion

    }
}
